package top.wilsonlv.jaguar.cloud.auth.security;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import top.wilsonlv.jaguar.cloud.handlerlog.client.component.HandlerLogInterceptor;
import top.wilsonlv.jaguar.security.component.JaguarLoginSuccessHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lvws
 * @since 2021/6/8
 */
@Slf4j
@Component
public class LoginSuccessHandler extends JaguarLoginSuccessHandler {

    @Autowired(required = false)
    private HandlerLogInterceptor handlerLogInterceptor;

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
                                        Authentication authentication) throws IOException {
        super.onAuthenticationSuccess(request, response, authentication);

        if (handlerLogInterceptor != null) {
            handlerLogInterceptor.log(request, response, null, null);
        }
    }

}
